/*
题目描述
用顺序存储实现栈的初始化、入栈、出栈、取栈顶、判栈空操作。调用以上操作实现判断从键盘输入的括号序列是否匹配。
输入
括号序列#（#为括号输入结束符号）
输出
匹配或不匹配
样例输入

{[()]}#

样例输出

匹配

*/
#include <iostream>
#include <cstring>
#include <stack>

using namespace std;

bool Compare(char right);
bool isValid(char* s);
char s[130] ;
stack<char> brackets;

int main()
{
	int i = 0;
	memset(s, 0, sizeof(s));
	char ch;
	while ((ch = getchar()) != '#') {
		s[i++] = ch;
	}
	if (isValid(s))
		printf("匹配");
	else
		printf("不匹配");
}
//与栈顶做比较
bool Compare(char right)
{
	char left = brackets.top();
	switch (right)
	{
	case '}':if (left != '{') return false;
		break;
	case ']':if (left != '[') return false;
		break;
	case ')':if (left != '(') return false;
		break;
	default:
		break;
	}
	return true;
}
//判断括号是否成对的函数 
bool isValid(char* s)
{
	int n = strlen(s);
	for (int i = 0; i < n; i++)
	{
		if (s[i] == '{' || s[i] == '(' || s[i] == '[')
		{
			brackets.push(s[i]);
		}
		else if (s[i] == '}' || s[i] == ')' || s[i] == ']')
		{
			if (Compare(s[i])) brackets.pop();
			else return false;
		}
	}
	if (brackets.empty()) return true;
	else return false;
}